using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls.Primitives;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class SelectAreaPage : BasePage
	{
		private DelegateSelectArea mCallBack;
		private static string loadedLanguage;
		private static List<AreaItem> provices;
		private static Dictionary<string, List<AreaItem>> provinceCityMap;
		private static List<string> proviceNames;
		public static DependencyProperty AreaFontSize_Property = DependencyProperty.Register("AreaFontSize", typeof(double), typeof(SelectAreaPage), new PropertyMetadata(40.0, null));
		private ApplicationBar mBar;
		internal BasePage thisPage;
		internal Grid LayoutRoot;
		internal TextBlock txtProvince;
		internal TextBlock txtCity;
		internal LoopingSelector provinceSelector;
		internal LoopingSelector citySelector;
		private bool _contentLoaded;
		public double AreaFontSize
		{
			get
			{
				return (double)base.GetValue(SelectAreaPage.AreaFontSize_Property);
			}
			set
			{
				base.SetValue(SelectAreaPage.AreaFontSize_Property, value);
			}
		}
		public static bool isChineseProvince(string provinceName)
		{
			if (provinceName != null && provinceName.get_Length() != 0)
			{
				SelectAreaPage.loadData();
				return SelectAreaPage.proviceNames != null && SelectAreaPage.proviceNames.Contains(provinceName);
			}
			return false;
		}
		public SelectAreaPage()
		{
			this.InitializeComponent();
			string text = null;
			string string_ = null;
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount != null)
			{
				text = this.trimToEmpty(curAccount.strProvince);
				string_ = this.trimToEmpty(curAccount.strCity);
			}
			this.AreaFontSize = (R.isEnglish() ? 30.0 : 35.0);
			AreaItem areaItem = default(AreaItem);
			AreaItem areaItem2 = default(AreaItem);
			SelectAreaPage.loadData();
			using (List<AreaItem>.Enumerator enumerator = SelectAreaPage.provices.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					AreaItem current = enumerator.get_Current();
					if (this.trimToEmpty(current.areaName).Equals(this.trimToEmpty(text)))
					{
						areaItem = current;
					}
				}
			}
			if (SelectAreaPage.provinceCityMap.ContainsKey(text))
			{
				List<AreaItem> list = SelectAreaPage.provinceCityMap.get_Item(text);
				using (List<AreaItem>.Enumerator enumerator2 = list.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						AreaItem current2 = enumerator2.get_Current();
						if (this.trimToEmpty(current2.areaName).Equals(this.trimToEmpty(string_)))
						{
							areaItem2 = current2;
						}
					}
				}
			}
			this.provinceSelector.DataSource = new ProviceDataSource(SelectAreaPage.provinceCityMap, this.citySelector, SelectAreaPage.provices);
			if (areaItem.areaName != null)
			{
				this.provinceSelector.DataSource.SelectedItem = areaItem;
			}
			if (areaItem2.areaName != null)
			{
				this.citySelector.DataSource.SelectedItem = areaItem2;
			}
			base.set_ApplicationBar(this.GetApplicationBar());
		}
		private static void loadData()
		{
			string currentLanguage = R.GetCurrentLanguage();
			if (currentLanguage == SelectAreaPage.loadedLanguage)
			{
				return;
			}
			SelectAreaPage.provices = new List<AreaItem>();
			SelectAreaPage.provinceCityMap = new Dictionary<string, List<AreaItem>>();
			SelectAreaPage.proviceNames = new List<string>();
			bool flag = R.isEnglish();
			string[] array = strings.Set_SelectArea_AreaData.Split(new char[]
			{
				','
			});
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string text = array2[i];
				if (text != null)
				{
					string text2 = text.Trim();
					int num = text2.IndexOf(':');
					if (num != -1)
					{
						string text3 = text2.Substring(0, num).Trim();
						AreaItem areaItem;
						areaItem.index = SelectAreaPage.provices.get_Count();
						areaItem.areaName = (flag ? text3 : SelectAreaPage.addLineChar(text3));
						SelectAreaPage.provices.Add(areaItem);
						SelectAreaPage.proviceNames.Add(text3);
						List<AreaItem> list = new List<AreaItem>();
						string[] array3 = text2.Substring(num + 1).Split(new char[]
						{
							'|'
						});
						string[] array4 = array3;
						for (int j = 0; j < array4.Length; j++)
						{
							string text4 = array4[j];
							if (text4 != null)
							{
								string text5 = text4.Trim();
								AreaItem areaItem2;
								areaItem2.index = list.get_Count();
								areaItem2.areaName = (flag ? text5 : SelectAreaPage.addLineChar(text5));
								list.Add(areaItem2);
							}
						}
						SelectAreaPage.provinceCityMap.Add(text3, list);
					}
				}
			}
			SelectAreaPage.loadedLanguage = currentLanguage;
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && 1 == object_0.Length && object_0[0] != null && object_0[0] is DelegateSelectArea)
			{
				this.mCallBack = (object_0[0] as DelegateSelectArea);
			}
			if (R.isEnglish())
			{
				Canvas.SetLeft(this.txtProvince, Canvas.GetLeft(this.txtProvince) - 68.0);
				Canvas.SetLeft(this.txtCity, Canvas.GetLeft(this.txtCity) - 20.0);
			}
		}
		protected override void OnPageOut()
		{
		}
		public IApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			this.mBar.set_Opacity(0.7);
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/ico_save.png", 2));
			applicationBarIconButton.set_Text(strings.COM_Confirm);
			applicationBarIconButton.add_Click(new EventHandler(this.saveButton_Click));
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			return this.mBar;
		}
		private void saveButton_Click(object sender, EventArgs e)
		{
			if (this.mCallBack != null)
			{
				string strTempPro = this.provinceSelector.DataSource.SelectedItem.ToString();
				string strTempCity = this.citySelector.DataSource.SelectedItem.ToString();
				this.mCallBack(strTempPro, strTempCity);
			}
			SelectCountryPage.shoudCloseOnBack = true;
			base.GoBack();
		}
		private void cancelButton_Click(object sender, EventArgs e)
		{
			base.GoBack();
		}
		private string trimToEmpty(string string_0)
		{
			if (string_0 != null)
			{
				return string_0.Trim().Replace("\n", "");
			}
			return "";
		}
		private static string addLineChar(string string_0)
		{
			return string_0;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Setting/SelectAreaPage.xaml", 2));
			this.thisPage = (BasePage)base.FindName("thisPage");
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txtProvince = (TextBlock)base.FindName("txtProvince");
			this.txtCity = (TextBlock)base.FindName("txtCity");
			this.provinceSelector = (LoopingSelector)base.FindName("provinceSelector");
			this.citySelector = (LoopingSelector)base.FindName("citySelector");
		}
	}
}
